<#-- 导入模版定义文件-->
<#include "../template/template_editPage.ftl">
<@edit title="课程管理">

<body class="input">
<script type="text/javascript">
	$().ready( function() {	
		var $validateErrorContainer = $("#validateErrorContainer");
		var $validateErrorLabelContainer = $("#validateErrorContainer ul");
		var $validateForm = $("#inputForm");
		var $tab = $("#tab");
	
		// Tab效果
		$tab.tabs(".tabContent", {
			tabs: "input"
		});
		
		// 表单验证
		$validateForm.validate({
			errorContainer: $validateErrorContainer,
			errorLabelContainer: $validateErrorLabelContainer,
			wrapper: "li",
			errorClass: "validateError",
			ignoreTitle: true,
			rules: {
				"courseInfo.courseName": {
						required: true,
						maxlength:30
				},
				"courseInfo.originalPrice": {
						required: true,
						number:true
				},
				"courseInfo.preferentialPrice": {
						required: true,
						number:true
				},
				"courseInfo.introduction":{
						maxlength:200
				},
				"courseInfo.beginReservationTime":{
						required: true
				},
				"courseInfo.endReservationTime":{
						required: true
				},
				"courseInfo.courseBeginTime":{
						required: true
				},
				"courseInfo.courseEndTime":{
						required: true
				},
				"courseInfo.teacherId":{
						required: true
				},
				"courseInfo.courseLimit":{
						required: true
				},
				"courseInfo.topicId":{
						required: true
				}
				
			},
			messages: {
				"courseInfo.courseName": {
						required: "请输入课程名称",
						maxlength: "课程名称必须在30个字符以内"
				},
				"courseInfo.originalPrice": {
						required: "请填写课程原价",
						number: "请填写正确的课程原价金额"
				} ,
				"courseInfo.preferentialPrice": {
						required: "请填写课程会员价",
						number: "请填写正确的课程会员价金额"
				},
				"courseInfo.introduction": {
						maxlength:"课程说明必须在200个字符以内"
				},
				"courseInfo.beginReservationTime":{
						required: "请选择课程预约开始时间"
				},
				"courseInfo.endReservationTime":{
						required: "请选择课程预约结束时间"
				},
				"courseInfo.courseBeginTime":{
						required: "请选择课程开始时间"
				},
				"courseInfo.courseEndTime":{
						required: "请选择课程结束时间"
				},
				"courseInfo.teacherId":{
						required: "请选择授课教师"
				},
				"courseInfo.courseLimit":{
						required: "请填写课程限额"
				},
				"courseInfo.topicId":{
						required: "请选择所属课题"
				}
			},
			submitHandler: function(form) {
				$(form).find(":submit").attr("disabled", true);
				form.submit();
			}
		});
		<#if actionErrors??&&(actionErrors?size > 0)>
			$.dialog({type: "warn", content: "<#list errorMessages as list>${list}<br></#list>",
			 modal: true, autoCloseTime: 3000});
		</#if>
		<#if actionMessages??&&(actionMessages?size > 0)>
			$.dialog({type: "success", content: "<#list actionMessages as list>${list}<br></#list>",
			 modal: true, autoCloseTime: 5000});
		</#if>
    
	});
	
function showDiv(picId,imgdiv,imgShow){
   		new uploadPreview({ UpBtn: picId, DivShow: imgdiv, ImgShow: imgShow });
	}
	
	function clearImg(imgId,imgShow){
		var obj = document.getElementById(imgId) ;   
		obj.outerHTML=obj.outerHTML;  
		
		$('#'+imgShow).attr("src", "");
	}
	

</script>
	<div class="body">
		<div class="inputBar">
			<h1><span class="icon">&nbsp;</span><#if courserId??>编辑课程<#else>发布课程</#if></h1>
		</div>
		<div style="display: none;" id="validateErrorContainer" class="validateErrorContainer">
			<div class="validateErrorTitle">以下信息填写有误,请重新填写</div>
				<ul></ul>
			</div>
		</div>		
		<form id="inputForm" class="validate" action="<#if courseId??>${web_base}/go/course!edit.htm<#else>${web_base}/go/course!save.htm</#if>" method="post" enctype="multipart/form-data">
			<input type="hidden" name="courseInfo.courseId" value="${(courseInfo.courseId)!}"/>
			<table class="inputTable tabContent">
				<tr>
					<th>
						课程名称：
					</th>
					<td>
						<input type="text" id="" name="courseInfo.courseName" class="formText {required: true}" value="${(courseInfo.courseName)!}" />
						<label id="labelUrl" class="requireField">*</label>
					</td>
				</tr>
				<tr>
					<th>
						课程子编号：
					</th>
					<td>
						<input type="text" id="" name="courseInfo.courseSubId" class="formText required" readonly="readonly" value="<#if courseSubId??>${(courseSubId)!}<#else>${(courseInfo.courseSubId)!}</#if>" />
						<label id="labelUrl" class="requireField">*</label>
					</td>
				</tr>
				<tr>
					<th>
						预约时间：
					</th>
					<td>
						<input type="text" id="startTime1" name="courseInfo.beginReservationTime"
                           onclick="WdatePicker({startDate:'%y',dateFmt:'yyyy-MM-dd'})"
                           value="${(courseInfo.beginReservationTime?string("yyyy-MM-dd"))!}" class="Wdate fixWidth" >
					<span>--</span>
					    <input type="text" id="endTime1" name="courseInfo.endReservationTime"
		                  onclick="WdatePicker({startDate:'%y',dateFmt:'yyyy-MM-dd',minDate:'#F{$dp.$D(\'startTime1\')}'})"
		                  value="${(courseInfo.endReservationTime?string("yyyy-MM-dd"))!}" class="Wdate fixWidth">
					</td>
				</tr>
				<tr>
					<th>
						课程日期：
					</th>
					<td>
							<input type="text" id="startTime" name="courseInfo.courseBeginTime"
                   			 onclick="WdatePicker({startDate:'%y',dateFmt:'yyyy-MM-dd'})"
                           value="${(courseInfo.courseBeginTime?string("yyyy-MM-dd"))!}" class="Wdate fixWidth" >
							<span>--</span>
							<input type="text" id="endTime" name="courseInfo.courseEndTime"
                	 		 onclick="WdatePicker({startDate:'%y',dateFmt:'yyyy-MM-dd',minDate:'#F{$dp.$D(\'startTime\')}'})"
                 		 	 value="${(courseInfo.courseEndTime?string("yyyy-MM-dd"))!}" class="Wdate fixWidth">
					</td>
				</tr>
				<tr>
					<th>
						所属课题：
					</th>
					<td>
						<select name="courseInfo.topicId" class="formText {required: true}" style="font-size: 14px">
						    <option value="" >请选择</option>
							<#if topicList??>
                        	<#list topicList as obj>
	                            <option value="${obj.topicId!}" <#if courseInfo?? && obj.topicId == courseInfo.topicId>selected</#if>>
		                           <#if obj.topicName?? && obj.topicName?length gte 15>
			                                <#--//截取输出文字的长度-->
			                                ${obj.topicName?substring(0,15)}...
			                        <#else>
		                                ${(obj.topicName)!}
		                            </#if>
                               </option>
		                        </#list>
		                    </#if>
						</select>
						<label class="requireField">*</label>
					</td>
				</tr>
				<tr>
					<th>
						课程费用：
					</th>
					<td>
						<input type="text"  name="courseInfo.originalPrice" class="formText {required: true}" value="${(courseInfo.originalPrice)!}" />--
						<input type="text"  name="courseInfo.preferentialPrice" class="formText {required: true}" value="${(courseInfo.preferentialPrice)!}" />
					</td>
				</tr>
				<tr>
					<th>
						课程限额：
					</th>
					<td>
						<input type="text" id="" name="courseInfo.courseLimit" class="formText {required: true}" value="${(courseInfo.courseLimit)!}" />
						<label id="labelUrl" class="requireField">*</label>
					</td>
				</tr>
				<tr>
					<th>
						授课教师：
					</th>
					<td>
						<select name="courseInfo.teacherId" class="formText {required: true}" style="font-size: 14px">
						    <option value="" >请选择</option>
							<#if teacherList??>
                        	<#list teacherList as obj>
	                            <option value="${obj.teacherId!}" <#if courseInfo?? && courseInfo.teacherId?? && obj.teacherId == courseInfo.teacherId>selected</#if>>
		                           <#if obj.teacherName?? && obj.teacherName?length gte 15>
			                                <#--//截取输出文字的长度-->
			                                ${obj.teacherName?substring(0,15)}...
			                        <#else>
		                                ${(obj.teacherName)!}
		                            </#if>
                               </option>
		                        </#list>
		                    </#if>
						</select>
						<label class="">授课时间：</label>
						<input type="text" id="startTime2" name="courseInfo.beginTeachTime"
                   			 onclick="WdatePicker({startDate:'%y',dateFmt:'yyyy-MM-dd HH:mm:ss'})"
                           value="${(courseInfo.beginTeachTime?string("yyyy-MM-dd HH:mm:ss"))!}" class="Wdate fixWidth" >
							<span>--</span>
							<input type="text" id="endTime2" name="courseInfo.endTeachTime"
                	 		 onclick="WdatePicker({startDate:'%y',dateFmt:'yyyy-MM-dd HH:mm:ss',minDate:'#F{$dp.$D(\'startTime2\')}'})"
                 		 	 value="${(courseInfo.endTeachTime?string("yyyy-MM-dd HH:mm:ss"))!}" class="Wdate fixWidth">
					</td>
				</tr>
				<tr>
					<th>
						课程图片：
					</th>
					<td>
					<div style="float:left">
    				<input type="file" id="coursePhoto" name="coursePhoto" value="添加图片" onclick="showDiv('coursePhoto','imgdiv1','imgShow1')"/>
						<div id="imgdiv1">
							<img id="imgShow1" width="160" height="100"  src="${(web_base + (courseInfo.coursePhoto))!}"/>
							<span class="spanLink" onclick="clearImg('imgdiv1','imgShow1')" title="删除">[删除]</span>
						</div>
					</div>
					</td>
				</tr>
				<tr>
					<th>
						课程说明：
					</th>
					<td>
						<textarea rows="8" cols="60" name="courseInfo.introduction" class="formText {}" >${(courseInfo.introduction)!}</textarea>
					</td>
				</tr>
			</table>
			<div class="buttonArea">
				<input type="submit" class="formButton" value="提  交" hidefocus="true" />&nbsp;&nbsp;&nbsp;&nbsp;
				<input type="button" class="formButton" onclick="window.history.back(); return false;" value="返  回" hidefocus="true" />
			</div>
		</form>
	</div>
</body>
</@edit>